package org.aplombh.java.leetcode.all;

public class _13罗马数字转整数 {

}

class Solution13_1 {
    public int romanToInt(String s) {
        s = s.replace("CM","a");
        s = s.replace("CD","b");
        s = s.replace("XC","c");
        s = s.replace("XL","d");
        s = s.replace("IX","e");
        s = s.replace("IV","f");

        int result = 0;
        for (int i=0; i<s.length(); i++) {
            result += value(s.charAt(i));
        }
        return result;
    }

    public int value(char ch) {
        switch(ch) {
            case 'I': return 1;
            case 'V': return 5;
            case 'X': return 10;
            case 'L': return 50;
            case 'C': return 100;
            case 'D': return 500;
            case 'M': return 1000;
            case 'a': return 900;
            case 'b': return 400;
            case 'c': return 90;
            case 'd': return 40;
            case 'e': return 9;
            case 'f': return 4;
        }
        return 0;
    }
}

